package IGU;

import javax.swing.JFrame;
import logica.FuncionesGUI;

/**
 *
 * @author Cristian
 */
public class AgregarUsuario extends javax.swing.JFrame {
    private JFrame ventanaPadre;

    /** Creates new form AgregarUsuario */
    public AgregarUsuario() {
        initComponents();
        initMyComponents();
    }
private boolean validate=false;
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        JTapellido = new javax.swing.JTextField();
        MainClave = new javax.swing.JLabel();
        MainNickname = new javax.swing.JLabel();
        MainNickname1 = new javax.swing.JLabel();
        MainNickname2 = new javax.swing.JLabel();
        JTnombre = new javax.swing.JTextField();
        MainNickname3 = new javax.swing.JLabel();
        JTNickName = new javax.swing.JTextField();
        JTPassword = new javax.swing.JPasswordField();
        MainNickname5 = new javax.swing.JLabel();
        MainNickname6 = new javax.swing.JLabel();
        JTtwitter = new javax.swing.JTextField();
        MainNickname7 = new javax.swing.JLabel();
        jDateNacimiento = new com.toedter.calendar.JDateChooser();
        jBAceptar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(51, 51, 51));
        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setLayout(null);

        JTapellido.setName("JTapellido"); // NOI18N
        jPanel1.add(JTapellido);
        JTapellido.setBounds(150, 130, 151, 20);

        MainClave.setFont(new java.awt.Font("Tahoma", 1, 11));
        MainClave.setForeground(new java.awt.Color(255, 255, 255));
        MainClave.setText("Cuenta");
        MainClave.setName("MainClave"); // NOI18N
        jPanel1.add(MainClave);
        MainClave.setBounds(180, 250, 70, 14);

        MainNickname.setFont(new java.awt.Font("Tahoma", 1, 14));
        MainNickname.setForeground(new java.awt.Color(255, 255, 255));
        MainNickname.setText("Nuevo Usuario");
        MainNickname.setName("MainNickname"); // NOI18N
        jPanel1.add(MainNickname);
        MainNickname.setBounds(170, 30, 120, 24);

        MainNickname1.setFont(new java.awt.Font("Tahoma", 1, 11));
        MainNickname1.setForeground(new java.awt.Color(255, 255, 255));
        MainNickname1.setText("Apellido:");
        MainNickname1.setName("MainNickname1"); // NOI18N
        jPanel1.add(MainNickname1);
        MainNickname1.setBounds(70, 130, 54, 24);

        MainNickname2.setFont(new java.awt.Font("Tahoma", 1, 11));
        MainNickname2.setForeground(new java.awt.Color(255, 255, 255));
        MainNickname2.setText("Nombre:");
        MainNickname2.setName("MainNickname2"); // NOI18N
        jPanel1.add(MainNickname2);
        MainNickname2.setBounds(70, 90, 54, 24);

        JTnombre.setName("JTnombre"); // NOI18N
        jPanel1.add(JTnombre);
        JTnombre.setBounds(150, 90, 151, 20);

        MainNickname3.setFont(new java.awt.Font("Tahoma", 1, 11));
        MainNickname3.setForeground(new java.awt.Color(255, 255, 255));
        MainNickname3.setText("Nickname:");
        MainNickname3.setName("MainNickname3"); // NOI18N
        jPanel1.add(MainNickname3);
        MainNickname3.setBounds(70, 280, 70, 24);

        JTNickName.setName("JTNickName"); // NOI18N
        jPanel1.add(JTNickName);
        JTNickName.setBounds(150, 280, 151, 20);

        JTPassword.setName("JTPassword"); // NOI18N
        jPanel1.add(JTPassword);
        JTPassword.setBounds(150, 320, 150, 20);

        MainNickname5.setFont(new java.awt.Font("Tahoma", 1, 11));
        MainNickname5.setForeground(new java.awt.Color(255, 255, 255));
        MainNickname5.setText("Password:");
        MainNickname5.setName("MainNickname5"); // NOI18N
        jPanel1.add(MainNickname5);
        MainNickname5.setBounds(70, 320, 70, 24);

        MainNickname6.setFont(new java.awt.Font("Tahoma", 1, 11));
        MainNickname6.setForeground(new java.awt.Color(255, 255, 255));
        MainNickname6.setText("Fecha de Nacimiento:");
        MainNickname6.setName("MainNickname6"); // NOI18N
        jPanel1.add(MainNickname6);
        MainNickname6.setBounds(70, 210, 130, 24);

        JTtwitter.setName("JTtwitter"); // NOI18N
        jPanel1.add(JTtwitter);
        JTtwitter.setBounds(150, 170, 151, 20);

        MainNickname7.setFont(new java.awt.Font("Tahoma", 1, 11));
        MainNickname7.setForeground(new java.awt.Color(255, 255, 255));
        MainNickname7.setText("Twitter:");
        MainNickname7.setName("MainNickname7"); // NOI18N
        jPanel1.add(MainNickname7);
        MainNickname7.setBounds(70, 170, 54, 24);

        jDateNacimiento.setName("jDateNacimiento"); // NOI18N
        jPanel1.add(jDateNacimiento);
        jDateNacimiento.setBounds(207, 210, 100, 20);

        jBAceptar.setText("Aceptar");
        jBAceptar.setName("jBAceptar"); // NOI18N
        jBAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAceptarActionPerformed(evt);
            }
        });
        jPanel1.add(jBAceptar);
        jBAceptar.setBounds(170, 390, 90, 23);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IGU/imagen/AddUser.png"))); // NOI18N
        jLabel1.setText("jLabel1");
        jLabel1.setName("jLabel1"); // NOI18N
        jPanel1.add(jLabel1);
        jLabel1.setBounds(330, 20, 70, 70);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("@");
        jLabel2.setName("jLabel2"); // NOI18N
        jPanel1.add(jLabel2);
        jLabel2.setBounds(140, 170, 20, 14);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 417, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAceptarActionPerformed

    validate=FuncionesGUI.ValidateAndAddUser(JTnombre,JTapellido,JTtwitter,jDateNacimiento,JTNickName,JTPassword);


        if (validate==true)
       {
        FuncionesGUI.habilitarVentana(this.ventanaPadre, true, true);
        this.dispose();
        }
 else
       {
 //se dispara ventana de error
         WarningAdd warning = new WarningAdd();

        FuncionesGUI.habilitarVentana(this, false, true);
        FuncionesGUI.habilitarVentana(warning, true, true);
        FuncionesGUI.ventanaSiempreEnTope(warning, true);
        warning.setVentanaPadre(this);
 }

        // TODO add your handling code here:
    }//GEN-LAST:event_jBAceptarActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
               FuncionesGUI.habilitarVentana(this.ventanaPadre, true, true);
        this.dispose();
        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowClosing

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AgregarUsuario().setVisible(true);
            }
        });
    }
      
    
     public JFrame getVentanaPadre()
    {
        return ventanaPadre;
    }
    public void setVentanaPadre(JFrame ventanaPadre)
    {
        this.ventanaPadre = ventanaPadre;
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField JTNickName;
    private javax.swing.JPasswordField JTPassword;
    private javax.swing.JTextField JTapellido;
    private javax.swing.JTextField JTnombre;
    private javax.swing.JTextField JTtwitter;
    private javax.swing.JLabel MainClave;
    private javax.swing.JLabel MainNickname;
    private javax.swing.JLabel MainNickname1;
    private javax.swing.JLabel MainNickname2;
    private javax.swing.JLabel MainNickname3;
    private javax.swing.JLabel MainNickname5;
    private javax.swing.JLabel MainNickname6;
    private javax.swing.JLabel MainNickname7;
    private javax.swing.JButton jBAceptar;
    private com.toedter.calendar.JDateChooser jDateNacimiento;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables

    private void initMyComponents() {
        JTnombre.setText("");
        JTapellido.setText("");
        JTtwitter.setText("");
        JTNickName.setText("");
        JTPassword.setText("");
    }

}
